﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace gt.IdentityServer.Data
{
    public class AppIdentityContext : DbContext
    {
        public AppIdentityContext(DbContextOptions<AppIdentityContext> options)
            : base(options)
        {

        }

        public DbSet<AppUser> Users { get; set; }
        public DbSet<AppUserGroup> UserGroups { get; set; }
        public DbSet<AppUserRole> UserRoles { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.ApplyConfiguration<AppUser>(new AppUserTypeConfigurations())
                .ApplyConfiguration<AppUserGroup>(new AppUserGroupTypeConfigurations())
                .ApplyConfiguration<AppUserRole>(new AppUserRoleTypeConfigurations())
                .ApplyConfiguration<AppUserRoleMapping>(new AppUserRoleMappingTypeConfigurations())
                .ApplyConfiguration<AppGroupRoleMapping>(new AppGroupRoleMappingTypeConfigurations());
        }
    }
}
